import { UC } from '@/api/config/servicePort'
import http from '@/api'
import { SelectOption, ResPage } from '@/api/interface'
import { Role } from './interface'

// 角色选项列表
export function listRoleOption() {
  return http.get<SelectOption[]>(UC + `/role/options`, undefined, { loading: false })
}

// 应用列表
export function pageRole(query: Role.Query) {
  return http.get<ResPage<Role.Record>>(UC + `/role/page`, query)
}

// 检查是否存在
export function checkExist(query: Role.CheckQuery) {
  return http.get<boolean>(UC + '/role/exist', query, { loading: false })
}

// 角色详情
export function getRole(id: string) {
  return http.get<Partial<Role.Form>>(UC + `/role`, { id }, { loading: false })
}

// 新增角色
export function addRole(form: Partial<Role.Form>) {
  return http.post(UC + `/role`, form)
}

// 修改角色
export function updateRole(form: Partial<Role.Form>) {
  return http.put(UC + `/role`, form)
}

// 删除角色
export function removeRole(id: string) {
  return http.delete(UC + `/role`, { id })
}

// 设置角色权限
export function setPermissions(menuIds: string[], roleId: string) {
  return http.put(UC + `/role/permissions`, { menuIds, roleId })
}

// 获取角色权限key数组
export function getPermissionKeys(id: string) {
  return http.get(UC + `/role/permission/keys`, { id }, { loading: false })
}
